package com.java.database;

import java.sql.*;

/**
 * @author wangning
 * @create 2021-04-26 15:05
 */
public class TestMysqlJdbc {

	public static void main(String[] args) {
		Connection connect = null;
		PreparedStatement statement = null;
		ResultSet resultSet = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbo?useUnicode=true&characterEncoding=utf-8", "root", "root");
			String sql = "SELECT * FROM tb_user WHERE user_name = '李四' limit 2";
//			for (int i = 0; i < 1500000 ; i++) {
//				String sql = "INSERT INTO `dbo`.`tb_user`(`user_id`, `user_name`, `user_sex`, `user_address`, `user_phone`, `user_imail`, `user_dept`, `user_level`, `user_status`) " +
//						"VALUES (null, '张三', '男', '中国', '15555555555', '123456@163.com', '特种部队', '一级', '正常');";
//				statement = connect.prepareStatement(sql);
//				statement.executeUpdate();
//			}
			System.out.println(System.currentTimeMillis());
			statement = connect.prepareStatement(sql);
			resultSet = statement.executeQuery();
			while (resultSet.next()) {
				int id = resultSet.getInt("user_id");
				System.out.println("id = " + id);
			}
			System.out.println(System.currentTimeMillis());
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (resultSet != null) resultSet.close();
				if (statement != null) statement.close();
				if (connect != null) connect.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
